import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:life_service/color/hex.dart';
import 'package:life_service/extensions/ex_widget.dart';
import 'package:life_service/model/hotel.dart';
import 'package:life_service/ui/custom_popup.dart';
import 'package:life_service/ui/draw_under_line.dart';
import 'package:life_service/utils/styles.dart';

import 'controller.dart';

class HotelListPage extends GetView<HotelListController> {
  const HotelListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        key: controller.appBarKey,
        backgroundColor: Colors.white,
        leading: Row(
          children: [
            IconButton(
              onPressed: Get.back,
              icon: Icon(
                CupertinoIcons.chevron_back,
                size: 20,
                color: HexColor(HexColor.color3333),
              ),
            ),
            Container(
              width: 54,
              height: 36,
              padding: const EdgeInsets.symmetric(vertical: 4),
              decoration: BoxDecoration(
                  color: HexColor(HexColor.colorF2f2),
                  borderRadius: BorderRadius.circular(4)),
              child: Column(
                children: [
                  Container(
                    height: 14,
                    alignment: Alignment.center,
                    child: Text.rich(
                      TextSpan(
                        children: [
                          TextSpan(
                            text: '住',
                            style: StylesUtils.customTextStyle(
                              color: HexColor.color9999,
                              fontSize: StylesUtils.fontSize10,
                            ),
                          ),
                          TextSpan(
                            text: '12-10',
                            style: StylesUtils.customTextStyle(
                              color: HexColor.colorFf00,
                              fontSize: StylesUtils.fontSize10,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 14,
                    alignment: Alignment.center,
                    child: Text.rich(
                      TextSpan(
                        children: [
                          TextSpan(
                            text: '离',
                            style: StylesUtils.customTextStyle(
                              color: HexColor.color9999,
                              fontSize: StylesUtils.fontSize10,
                            ),
                          ),
                          TextSpan(
                            text: '12-11',
                            style: StylesUtils.customTextStyle(
                              color: HexColor.colorFf00,
                              fontSize: StylesUtils.fontSize10,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
        leadingWidth: 110,
        title: TextField(
          style: StylesUtils.customTextStyle(
            color: HexColor.color3333,
          ),
          decoration: InputDecoration(
            constraints: const BoxConstraints.expand(width: 218, height: 36),
            prefixIconConstraints:
                const BoxConstraints.expand(width: 40, height: 36),
            prefixIcon: IconButton(
              onPressed: () {},
              icon: Icon(
                CupertinoIcons.search,
                size: 18,
                color: HexColor(HexColor.color9999),
              ),
            ),
            suffixIconConstraints:
                const BoxConstraints.expand(width: 40, height: 36),
            suffixIcon: IconButton(
              onPressed: () {},
              icon: Icon(
                CupertinoIcons.xmark_circle_fill,
                size: 16,
                color: HexColor(HexColor.color9999),
              ),
            ),
            filled: true,
            fillColor: HexColor(HexColor.colorF7f7),
            hintText: '北海海城区',
            hintStyle: StylesUtils.customTextStyle(
              color: HexColor.color9999,
              fontSize: StylesUtils.fontSize13,
            ),
            focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(8),
                borderSide: BorderSide.none),
            border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(8),
                borderSide: BorderSide.none),
            enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(8),
                borderSide: BorderSide.none),
            isCollapsed: true,
            isDense: true,
            contentPadding: const EdgeInsets.only(top: 12, left: 15),
          ),
          onSubmitted: (String keyword) {},
          onChanged: (String query) {},
          onTap: () {},
          textInputAction: TextInputAction.search,
          onTapOutside: (event) {},
        ),
        actions: [
          IconButton(
            onPressed: () {},
            icon: Icon(
              CupertinoIcons.map_fill,
              size: 19,
              color: HexColor(HexColor.color0e0e),
            ),
          ),
        ],
        shadowColor: HexColor(HexColor.colorF2f2),
        elevation: 1,
        bottom: PreferredSize(
          preferredSize: const Size.fromHeight(44),
          child: SizedBox(
            height: 44,
            child: Row(
              children: controller.selected
                  .map(
                    (str) => Expanded(
                      child: Center(
                        child: Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: '$str ',
                                style: StylesUtils.customTextStyle(
                                  fontWeight: FontWeight.w700,
                                  color: HexColor.color3333,
                                ),
                              ),
                              WidgetSpan(
                                child: Icon(
                                  CupertinoIcons.chevron_down,
                                  color: HexColor(
                                    HexColor.color9999,
                                  ),
                                  size: 12,
                                ),
                                alignment: PlaceholderAlignment.middle,
                              )
                            ],
                          ),
                        ),
                      ).onTap(() {
                        switch (str) {
                          case '位置区域':
                            return openPopup(
                                controller.appBarKey.currentContext!);
                          case '价格等级':
                            return showPopup(
                                context: controller.appBarKey.currentContext!,
                                builder: (_) {
                                  return Container(
                                    height: 330,
                                    color: Colors.white,
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Expanded(
                                          child: SingleChildScrollView(
                                            padding: const EdgeInsets.symmetric(
                                                horizontal: 20),
                                            child: Column(
                                              children: [
                                                Container(
                                                  padding:
                                                      const EdgeInsets.only(
                                                          top: 15, bottom: 15),
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Obx(
                                                    () => Text.rich(
                                                      TextSpan(
                                                        children: [
                                                          TextSpan(
                                                            text: '价格',
                                                            style: StylesUtils
                                                                .customTextStyle(
                                                                    color: HexColor
                                                                        .color3333),
                                                          ),
                                                          TextSpan(
                                                            text:
                                                                '  ${controller.tag}',
                                                            style: StylesUtils
                                                                .customTextStyle(
                                                              color: HexColor
                                                                  .colorFf62,
                                                            ),
                                                          )
                                                        ],
                                                      ),
                                                    ),
                                                  ),
                                                ),
                                                StaggeredGrid.count(
                                                  crossAxisCount: 4,
                                                  crossAxisSpacing: 10,
                                                  mainAxisSpacing: 15,
                                                  children: controller.price
                                                      .asMap()
                                                      .map(
                                                        (key, value) =>
                                                            MapEntry(
                                                          key,
                                                          Obx(
                                                            () => Container(
                                                              height: 36,
                                                              decoration:
                                                                  activeBox(
                                                                      key,
                                                                      controller
                                                                          .tagIdx
                                                                          .value),
                                                              alignment:
                                                                  Alignment
                                                                      .center,
                                                              child: Text(
                                                                value,
                                                                style: StylesUtils
                                                                    .customTextStyle(
                                                                  color: controller
                                                                              .tagIdx
                                                                              .value ==
                                                                          key
                                                                      ? HexColor
                                                                          .colorFf62
                                                                      : HexColor
                                                                          .color6666,
                                                                  fontSize:
                                                                      StylesUtils
                                                                          .fontSize13,
                                                                ),
                                                              ),
                                                            ).onTap(() {
                                                              controller.tagIdx
                                                                  .value = key;
                                                              controller.tag
                                                                      .value =
                                                                  value;
                                                            }),
                                                          ),
                                                        ),
                                                      )
                                                      .values
                                                      .toList(),
                                                ),
                                                Container(
                                                  padding:
                                                      const EdgeInsets.only(
                                                          top: 20, bottom: 15),
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '酒店类型',
                                                    style: StylesUtils
                                                        .customTextStyle(
                                                      color: HexColor.color3333,
                                                    ),
                                                  ),
                                                ),
                                                StaggeredGrid.count(
                                                  crossAxisCount: 4,
                                                  crossAxisSpacing: 10,
                                                  mainAxisSpacing: 15,
                                                  children: controller.hotel
                                                      .asMap()
                                                      .map(
                                                        (key, value) =>
                                                            MapEntry(
                                                          key,
                                                          Obx(
                                                            () => Container(
                                                              height: 36,
                                                              decoration: activeBox(
                                                                  key,
                                                                  controller
                                                                      .hotelIdx
                                                                      .value),
                                                              alignment:
                                                                  Alignment
                                                                      .center,
                                                              child: Text(
                                                                value,
                                                                style: StylesUtils
                                                                    .customTextStyle(
                                                                  color: controller
                                                                              .hotelIdx
                                                                              .value ==
                                                                          key
                                                                      ? HexColor
                                                                          .colorFf62
                                                                      : HexColor
                                                                          .color6666,
                                                                  fontSize:
                                                                      StylesUtils
                                                                          .fontSize13,
                                                                ),
                                                              ),
                                                            ).onTap(() {
                                                              controller
                                                                  .hotelIdx
                                                                  .value = key;
                                                            }),
                                                          ),
                                                        ),
                                                      )
                                                      .values
                                                      .toList(),
                                                )
                                              ],
                                            ),
                                          ),
                                        ),
                                        SizedBox(
                                          height: 44,
                                          child: Row(
                                            children: [
                                              Expanded(
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  decoration: BoxDecoration(
                                                    border: Border.all(
                                                      color: HexColor(
                                                          HexColor.colorF2f2),
                                                    ),
                                                  ),
                                                  child: Text(
                                                    '重置',
                                                    style: StylesUtils
                                                        .customTextStyle(
                                                      color: HexColor.color3333,
                                                    ),
                                                  ),
                                                ),
                                              ),
                                              Expanded(
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  color: HexColor(
                                                      HexColor.colorFf62),
                                                  child: Text(
                                                    '确定',
                                                    style: StylesUtils
                                                        .customTextStyle(),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                  );
                                });
                          case '智能排序':
                            return showPopup(
                                context: controller.appBarKey.currentContext!,
                                builder: (_) {
                                  return Container(
                                    height: controller.sort.length * 47,
                                    color: Colors.white,
                                    padding: EdgeInsets.symmetric(
                                        horizontal: (Get.width - 335) / 2),
                                    child: ListView.builder(
                                      itemBuilder: (_, i) {
                                        return DrawUnderLine(
                                          child: Container(
                                            height: 47,
                                            alignment: Alignment.centerLeft,
                                            child: Text(
                                              controller.sort[i],
                                              style:
                                                  StylesUtils.customTextStyle(
                                                color: HexColor.color3333,
                                              ),
                                            ),
                                          ),
                                        );
                                      },
                                      itemCount: controller.sort.length,
                                      itemExtent: 47,
                                    ),
                                  );
                                });
                          case '筛选':
                            return showPopup(
                                context: controller.appBarKey.currentContext!,
                                builder: (_) {
                                  return Container(
                                    height: 300,
                                    color: Colors.white,
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Expanded(
                                          child: Row(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: [
                                              Container(
                                                width: 100,
                                                color: HexColor(
                                                    HexColor.colorF2f2),
                                                child: ListView(
                                                  itemExtent: 47,
                                                  children: [
                                                    Container(
                                                      height: 47,
                                                      alignment:
                                                          Alignment.center,
                                                      color: Colors.white,
                                                      child: Text(
                                                        '酒店类',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                          color: HexColor
                                                              .colorFf62,
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      height: 47,
                                                      alignment:
                                                          Alignment.center,
                                                      child: Text(
                                                        '酒店品牌',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                          color: HexColor
                                                              .color3333,
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      height: 47,
                                                      alignment:
                                                          Alignment.center,
                                                      child: Text(
                                                        '房建类型',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                          color: HexColor
                                                              .color3333,
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      height: 47,
                                                      alignment:
                                                          Alignment.center,
                                                      child: Text(
                                                        '设施服务',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                          color: HexColor
                                                              .color3333,
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      height: 47,
                                                      alignment:
                                                          Alignment.center,
                                                      child: Text(
                                                        '优惠活动',
                                                        style: StylesUtils
                                                            .customTextStyle(
                                                          color: HexColor
                                                              .color3333,
                                                        ),
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                              ),
                                              Expanded(
                                                child: SingleChildScrollView(
                                                  padding:
                                                      const EdgeInsets.only(
                                                          left: 15, right: 15),
                                                  child: StaggeredGrid.count(
                                                    crossAxisCount: 3,
                                                    crossAxisSpacing: 10,
                                                    mainAxisSpacing: 15,
                                                    children: controller.screen
                                                        .asMap()
                                                        .map(
                                                          (key, value) =>
                                                              MapEntry(
                                                            key,
                                                            Obx(
                                                              () => Container(
                                                                height: 36,
                                                                alignment:
                                                                    Alignment
                                                                        .center,
                                                                decoration: activeBox(
                                                                    key,
                                                                    controller
                                                                        .screenIdx
                                                                        .value),
                                                                child: Text(
                                                                  value,
                                                                  style: StylesUtils
                                                                      .customTextStyle(
                                                                    color: key ==
                                                                            controller
                                                                                .screenIdx.value
                                                                        ? HexColor
                                                                            .colorFf62
                                                                        : HexColor
                                                                            .color6666,
                                                                    fontSize:
                                                                        StylesUtils
                                                                            .fontSize13,
                                                                  ),
                                                                ),
                                                              ).onTap(() {
                                                                controller
                                                                    .screenIdx
                                                                    .value = key;
                                                              }),
                                                            ),
                                                          ),
                                                        )
                                                        .values
                                                        .toList(),
                                                  ),
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                        SizedBox(
                                          height: 44,
                                          child: Row(
                                            children: [
                                              Expanded(
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  decoration: BoxDecoration(
                                                    border: Border.all(
                                                      color: HexColor(
                                                          HexColor.colorF2f2),
                                                    ),
                                                  ),
                                                  child: Text(
                                                    '重置',
                                                    style: StylesUtils
                                                        .customTextStyle(
                                                      color: HexColor.color3333,
                                                    ),
                                                  ),
                                                ),
                                              ),
                                              Expanded(
                                                child: Container(
                                                  alignment: Alignment.center,
                                                  color: HexColor(
                                                      HexColor.colorFf62),
                                                  child: Text(
                                                    '确定',
                                                    style: StylesUtils
                                                        .customTextStyle(),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                  );
                                });
                        }
                      }),
                    ),
                  )
                  .toList(),
            ),
          ),
        ),
      ),
      body: NotificationListener(
        onNotification: (ScrollNotification notification) {
          if (notification is OverscrollNotification) {
            if (notification.metrics.pixels >=
                    notification.metrics.maxScrollExtent &&
                !controller.isLoading.value &&
                controller.pageSize.value < controller.total) {
              controller.loadMore();
            }
          }
          return true;
        },
        child: CustomScrollView(
          physics: const AlwaysScrollableScrollPhysics(),
          slivers: [
            PinnedHeaderSliver(
              child: Container(
                height: 50,
                padding: const EdgeInsets.only(left: 20),
                decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border(
                    bottom: BorderSide(
                      color: HexColor(HexColor.colorF2f2),
                    ),
                  ),
                ),
                alignment: Alignment.centerLeft,
                child: Wrap(
                  spacing: 10,
                  crossAxisAlignment: WrapCrossAlignment.center,
                  children: controller.types
                      .map(
                        (e) => Obx(
                          () => Container(
                            constraints: const BoxConstraints.expand(
                                width: 75, height: 28),
                            decoration: activeDecoration(e.value),
                            alignment: Alignment.center,
                            child: Text(
                              e.value.name,
                              style: StylesUtils.customTextStyle(
                                color: e.value.checked
                                    ? HexColor.colorFf62
                                    : HexColor.color6666,
                                fontSize: StylesUtils.fontSize12,
                              ),
                            ),
                          ).onTap(() {
                            e.update((f) => f?.checked = !f.checked);
                          }),
                        ),
                      )
                      .toList(),
                ),
              ),
            ),
            SliverPadding(
              padding: EdgeInsets.symmetric(
                  vertical: 15, horizontal: (Get.width - 334) / 2),
              sliver: Obx(
                () => SliverAlignedGrid.count(
                  itemBuilder: (_, i) {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Stack(
                          children: [
                            ClipRRect(
                              borderRadius: BorderRadius.circular(5.r),
                              child: Image.network(
                                'https://img2.baidu.com/it/u=1407638119,2449258627&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=235',
                                width: double.infinity,
                                height: 110,
                                fit: BoxFit.fill,
                              ),
                            ),
                            Positioned(
                              top: 8,
                              right: 20,
                              child: Container(
                                constraints: const BoxConstraints.expand(
                                    width: 82, height: 20),
                                decoration: BoxDecoration(
                                  color:
                                      HexColor.rgba(0, 0, 0, 0.498039215686275),
                                  borderRadius: BorderRadius.circular(10),
                                ),
                                alignment: Alignment.center,
                                child: Text(
                                  '南锣鼓巷附近',
                                  style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize10,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 10),
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '锦江之星（背景王府井店）',
                            style: StylesUtils.customTextStyle(
                              fontWeight: FontWeight.w700,
                              color: HexColor.color3333,
                            ),
                          ),
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 5),
                          alignment: Alignment.centerLeft,
                          child: Wrap(
                            spacing: 10,
                            alignment: WrapAlignment.start,
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              Text(
                                '4.6分',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color28d0,
                                  fontWeight: FontWeight.w700,
                                ),
                              ),
                              Text(
                                '5000+消费',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                  fontSize: StylesUtils.fontSize12,
                                ),
                              ),
                            ],
                          ),
                        ),
                        Container(
                          margin: const EdgeInsets.only(top: 5),
                          alignment: Alignment.centerLeft,
                          child: Wrap(
                            spacing: 10,
                            alignment: WrapAlignment.start,
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              Text(
                                '360',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.colorFf62,
                                  fontWeight: FontWeight.w700,
                                  fontSize: StylesUtils.fontSize16,
                                ),
                              ),
                              Text(
                                '起',
                                style: StylesUtils.customTextStyle(
                                    fontSize: StylesUtils.fontSize12,
                                    color: HexColor.color9999),
                              ),
                              Container(
                                constraints: const BoxConstraints.expand(
                                    width: 55, height: 20),
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                  border: Border.all(
                                    color: HexColor(HexColor.colorFfc7),
                                  ),
                                ),
                                child: Text(
                                  '新人红包',
                                  style: StylesUtils.customTextStyle(
                                    color: HexColor.colorFfc7,
                                    fontSize: StylesUtils.fontSize10,
                                  ),
                                ),
                              )
                            ],
                          ),
                        )
                      ],
                    );
                  },
                  crossAxisCount: 2,
                  crossAxisSpacing: 14,
                  mainAxisSpacing: 20,
                  itemCount: controller.pageSize.value,
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Obx(() {
                if (controller.pageSize.value >= controller.total) {
                  return Container(
                    padding: const EdgeInsets.all(10),
                    alignment: Alignment.center,
                    child: Text(
                      '~~已经到底了~~',
                      style: StylesUtils.customTextStyle(
                        fontSize: StylesUtils.fontSize15,
                        color: HexColor.color3333,
                      ),
                    ),
                  );
                }
                if (controller.isLoading.value) {
                  return Container(
                    padding: const EdgeInsets.all(10),
                    alignment: Alignment.center,
                    child: const CircularProgressIndicator(
                      strokeWidth: 3,
                    ),
                  );
                }
                return Container(
                  padding: const EdgeInsets.all(10),
                  alignment: Alignment.center,
                  child: Text(
                    '~~下拉加载数据~~',
                    style: StylesUtils.customTextStyle(
                      fontSize: StylesUtils.fontSize15,
                      color: HexColor.color3333,
                    ),
                  ),
                );
              }),
            ),
          ],
        ),
      ),
    );
  }

  BoxDecoration activeBox(int index, int activeIdx) {
    if (activeIdx == index) {
      return BoxDecoration(
        borderRadius: BorderRadius.circular(4),
        color: HexColor('#FFF0F0'),
      );
    }
    return BoxDecoration(
      borderRadius: BorderRadius.circular(4),
      border: Border.all(
        color: HexColor(HexColor.colorF2f2),
      ),
    );
  }

  void openPopup(BuildContext context) {
    showPopup(
        context: context,
        builder: (_) {
          return Container(
            color: Colors.white,
            height: 370,
            child: Column(
              children: [
                Expanded(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: 100,
                        color: HexColor(HexColor.colorF2f2),
                        child: ListView(
                          itemExtent: 47,
                          children: [
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              color: Colors.white,
                              child: Text(
                                '商圈',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.colorFf62,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '景点',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '地铁线',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '机场车站',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '医院周边',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '高校周边',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                            Container(
                              height: 47,
                              alignment: Alignment.center,
                              child: Text(
                                '行政区',
                                style: StylesUtils.customTextStyle(
                                  color: HexColor.color3333,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Expanded(
                        child: ListView(
                          padding: const EdgeInsets.only(left: 15),
                          children: [
                            for (var i = 0; i < 10; i++)
                              DrawUnderLine(
                                child: Container(
                                  height: 47,
                                  alignment: Alignment.centerLeft,
                                  child: Text(
                                    '中关村/五道口',
                                    style: StylesUtils.customTextStyle(
                                      color: HexColor.color3333,
                                    ),
                                  ),
                                ),
                              ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
                SizedBox(
                  height: 44,
                  child: Row(
                    children: [
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: HexColor(HexColor.colorF2f2),
                            ),
                          ),
                          child: Text(
                            '重置',
                            style: StylesUtils.customTextStyle(
                              color: HexColor.color3333,
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          color: HexColor(HexColor.colorFf62),
                          child: Text(
                            '确定',
                            style: StylesUtils.customTextStyle(),
                          ),
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          );
        });
  }

  void showPopup(
      {required BuildContext context,
      required WidgetBuilder builder,
      double? elevation,
      Color? shadowColor,
      Duration animationDuration = const Duration(milliseconds: 200)}) {
    final RenderBox button = context.findRenderObject()! as RenderBox;

    debugPrint('button = ${button.size}');

    final RenderBox overlay =
        Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox;

    debugPrint('overlay = ${overlay.size} \twidth = ${Get.width}');

    Offset offset = Offset(0.0, button.size.height);

    debugPrint('bottom = ${button.size.bottomRight(Offset.zero)}');

    RelativeRect position = RelativeRect.fromRect(
      Rect.fromPoints(
        button.localToGlobal(offset, ancestor: overlay),
        button.localToGlobal(Offset(Get.width, 0) + offset, ancestor: overlay),
      ),
      Offset.zero & overlay.size,
    );

    Navigator.of(context).push(
      CustomPopupRoute(
          position: position,
          builder: builder,
          elevation: elevation,
          shadowColor: shadowColor,
          animationDuration: animationDuration,
          barrierLabel:
              MaterialLocalizations.of(context).modalBarrierDismissLabel),
    );
  }

  BoxDecoration activeDecoration(HotelTypeModel value) {
    if (value.checked) {
      return BoxDecoration(
        color: HexColor('#FFF0F0'),
        borderRadius: BorderRadius.circular(4),
      );
    }
    return BoxDecoration(
      borderRadius: BorderRadius.circular(4),
      border: Border.all(
        color: HexColor(HexColor.colorF2f2),
      ),
    );
  }
}
